home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / text / cedispel.lha / CEDispell / Spell.ced next >
Text File  |  1995-08-25  |  5KB  |  193 lines

  1. /* $Revision Header built automatically *************** (do not edit) ************
  2. **
  3. ** © Copyright by Thule Software
  4. **
  5. ** File             : HardCore:Text/Programs/CED/CEDRexx/Spell.ced
  6. ** Created on       : Torsdag, 03.08.95 14:01:26
  7. ** Created by       : Nils Peter Sudmann
  8. ** Current revision : V1.3
  9. **
  10. **
  11. ** Purpose
  12. ** -------
  13. **     ARexx program to spellcheck current CED file.
  14. **     Needs ispell and rexxreqtools.library.
  15. **
  16. ** Revision V1.3
  17. ** --------------
  18. ** created on Fredag, 25.08.95 00:33:53  by  Nils Peter Sudmann.   LogMessage :
  19. **   - Revision 1.1 fixed an non-existing bug ;) This is getting 
  20. **     confusing. Removed the useless fix.
  21. **
  22. ** Revision V1.2
  23. ** --------------
  24. ** created on Fredag, 25.08.95 00:23:42  by  Nils Peter Sudmann.   LogMessage :
  25. **   - Added a check to see if the current view really was
  26. **     saved to a file.
  27. **
  28. ** Revision V1.1
  29. ** --------------
  30. ** created on Torsdag, 17.08.95 22:21:47  by  Nils Peter Sudmann.   LogMessage :
  31. **   - Fixed bug when file was stored in a root device. Ie. the
  32. **     path ended with a ':' instead of a '/'.
  33. **
  34. ** Revision V1.0
  35. ** --------------
  36. ** created on Torsdag, 03.08.95 14:01:26  by  Nils Peter Sudmann.   LogMessage :
  37. **     --- Initial release ---
  38. **
  39. *********************************************************************************/
  40. ispellcmd = 'run <nil: >nil: ispell -r -pHardCore:users/nilss/.ispell >nil: <nil:'
  41. ispelldeftemp = 'T:'
  42. cr='0A'X
  43.  
  44. call addlib('rexxreqtools.library',5,-30)
  45. options results
  46. status 19
  47. filename = result
  48. status 21
  49. if result = '' then do
  50.   call rtezrequest('Save your view to a file first.','OK','Spell...');
  51.   call Quit
  52.   exit 0
  53. end
  54. if ~show(ports, 'IRexxSpell') then
  55.   do
  56.     address command ispellcmd
  57.     address command waitforport 'IRexxSpell'
  58.     if rc=5 then do
  59.       call rtezrequest('Unable to find port IRexxSpell.'cr'Check your paths.'cr||ispellcmd,'OK','Spell...');
  60.       call Quit
  61.       exit 0
  62.     end
  63.   end
  64.  
  65. fname_clip = address() || 'file' || filename
  66. pos_clip = address() || 'pos' || filename
  67. posx_clip = address() || 'x' || filename
  68. posy_clip = address() || 'y' || filename
  69. xx = getclip(posx_clip)
  70. yy = getclip(posy_clip)
  71.  
  72. errfname = getclip(fname_clip)
  73. pos = getclip(pos_clip)
  74.  
  75. if errfname == '' then do
  76.   pos = 0; xx = 0; yy = 0
  77.   address 'IRexxSpell' filecheck filename
  78.   errfname = result
  79.   if pos('Error', errfname) ~= 0 then do
  80.     call rtzrequest('ISpell 'errfname,'OK','Spell...');
  81.     call Quit
  82.     exit 0
  83.   end
  84.  
  85.   split = lastpos('/', errfname )
  86.   errfname = ispelldeftemp||substr(errfname, split +1)
  87.   pos = 0
  88.   call setclip fname_clip, errfname
  89. end
  90. if open('err', errfname,'r') = 0 then do
  91.   call rtzrequest('Can''t find '||errfname||'!','OK','Spell...');
  92.   call Quit
  93.   exit 0
  94. end
  95.  
  96. seek('err', pos, 'BEGIN')
  97. word = readln('err')
  98. pos = seek('err', 0, 'Current')
  99. call setclip pos_clip, pos
  100. close('err')
  101. if word = "" then do
  102.   call Quit
  103.   exit 0
  104. end
  105.  
  106. address 'IRexxSpell' check word
  107. parse var result type' 'word' '.' 'choices
  108. jumpto yy+1 xx+1
  109. search for... word 0 0 1 1
  110. if (result = 0) then do
  111.   call rtezrequest('Failed search for "'||word||'"!'||cr||'You have probably modified the file.'||cr||'Please save and try again.','OK','Spell...')
  112.   call Quit
  113.   exit 0
  114. end
  115.  
  116. status 46
  117. setclip(posx_clip,result)
  118. status 47
  119. setclip(posy_clip,result)
  120. if choices = '' then do
  121.   res = rtezrequest('No suggestion for "'word||'".','OK|_Options|_Cancel','Spell...')
  122.   if (res=2) then
  123.     call Options
  124.   exit 0
  125. end
  126. else do
  127.   cc = 0
  128.   rest = choices
  129.   do while (rest ~= '')
  130.     cc = cc + 1
  131.     parse var rest c.cc', 'rest
  132.   end
  133.   dcc = 1
  134.   do forever
  135.     btext = 'Misspelled word: "'||word||'" (with '||cc||' suggestions).'||cr
  136.     gad = 'More..'
  137.     do i=dcc for Min(dcc+4, cc)-dcc+1
  138.       btext = btext||cr||i||': '||c.i
  139.       gad = gad||'|_'||i
  140.     end
  141.     res = rtezrequest(btext,gad||'|_Options|_Cancel','Suggestions...')
  142.     if (res = i+2-dcc) then
  143.       call Options
  144.     else do
  145.       if (res = 1) then do
  146.         if (dcc+5 > cc) then
  147.           dcc = 1
  148.         else
  149.           dcc = dcc+5
  150.       end
  151.     end
  152.     if (res ~= 1) then break
  153.   end
  154.   cc = res+dcc-2
  155.   select
  156.     when (res < 2) then
  157.       nop
  158.     when (res < i+2-dcc) then do
  159. /*      'delete word'
  160.       Text c.cc*/
  161.       LEFT
  162.       replace word '"'c.cc'"'
  163.     end
  164.     otherwise
  165.       nop
  166.   end
  167. end
  168. exit 0
  169. end
  170.  
  171. Options:
  172. res2 = rtezrequest('Misspelled word: "'||word||'".'||cr||'What should I do?',"Accept|_Add|_Quit|_Cancel",'Options...')
  173.   select
  174.   when (res2 = 1) then
  175.     address 'IRexxSpell' ACCEPT word
  176.   when (res2 = 2) then
  177.     address 'IRexxSpell' ADD word
  178.   when (res2 = 3) then
  179.     call Quit
  180.   when (res2 = 0) then
  181.     res = 1
  182.   end
  183. return
  184.  
  185. Quit:
  186.   call rtezrequest('No more misspellings were found!','OK','Spell...')
  187.   address command 'delete >nil: '||errfname
  188.   setclip(pos_clip)
  189.   setclip(posx_clip)
  190.   setclip(posy_clip)
  191.   setclip(fname_clip)
  192. return
  193.